package deprecated;

import java.util.Arrays;

/**
 * redundant class, implementation of the edit distance algorithm, functionality provided by
 * DistanceSet.java object.
 * 
 */
public class LevenshteinDistance {
	//http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#Java
	//hier nur wenig modifiziert

        private static int minimum(int a, int b, int c) {
                return Math.min(Math.min(a, b), c);
        }
 
        public static int compLevDist(CharSequence str1,
                        CharSequence str2) {
                int[][] distance = new int[str1.length() + 1][str2.length() + 1];
 
                for (int i = 0; i <= str1.length(); i++)
                        distance[i][0] = i;
                for (int j = 1; j <= str2.length(); j++)
                        distance[0][j] = j;
                for (int i = 1; i <= str1.length(); i++)
                        for (int j = 1; j <= str2.length(); j++)
                                distance[i][j] = minimum(
                                                distance[i - 1][j] + 1,
                                                distance[i][j - 1] + 1,
                                                distance[i - 1][j - 1]
                                                                + ((str1.charAt(i - 1) == str2.charAt(j - 1)) ? 0
                                                                                : 1));
 
                return distance[str1.length()][str2.length()];
        }
        
      public static int calcMin (int[] numbers){
    		int min = 9999999;
    		for (int num : numbers){
    			int tmp = num;
    			if(tmp < min){
    				min = tmp;
    			}
    		}
    		return min;
    	}
    	
    	public static void generateMatchPath(String[] source, String[] tmsource){
    		
    		for (int i=0; i<source.length; i++){
    			int[] lev = new int[tmsource.length];
    			for (int j=0; j<tmsource.length; j++){
    				lev[j] = deprecated.LevenshteinDistance.compLevDist(source[i], tmsource[j]);
    			}
    			System.out.println(Arrays.toString(lev));
    		}
    	}

        public static void main(String[] args){
        	
        	System.out.println(compLevDist("hallo", "hello"));
        	System.out.println(compLevDist("hallo", "bello"));
        	System.out.println(compLevDist("hallo", "hallole"));
        	System.out.println(compLevDist("hallo", "kanone"));
        	
        	generateMatchPath("Das ist der kurze dumme Satz".split(" "), "Das ist ein komplizierterer zweiter dummer Satz".split(" "));
    		
    		int[] a = new int[]{92, 16, 99, 15, 77, 89};
    		System.out.println(calcMin(a));
        }

}
